import {Episode} from './models/episode.model';
import {Course} from './models/course.model';
import {Global, Module} from '@nestjs/common';
import {DbService} from './db.service';
import {User} from '@libs/db/models/user.model';
import {TypegooseModule} from 'nestjs-typegoose';
import {ConfigService} from "@nestjs/config";
import {EnvEnum} from "@app/common/enum/envEnum";
import {Action} from "@libs/db/models/action.model";
import {Comment} from "@libs/db/models/comment.model";
import {Category} from "@libs/db/models/category.model";

const models = TypegooseModule.forFeature([User, Course, Episode, Action, Comment, Category]);

@Global()
@Module({
  imports: [
    TypegooseModule.forRootAsync({
      useFactory(configService: ConfigService) {
        return {uri: configService.get<string>('env')[EnvEnum.db_url] || 'mongodb://localhost:27017/topfullstack'}
      },
      inject: [ConfigService]
    }),
    models,
  ],
  providers: [DbService],
  exports: [DbService, models],
})
export class DbModule {
}
